package com.turnengine.client.local.alliance.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Alliance.
 */
public class Alliance implements IAlliance, Comparable<IAlliance> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The leader id. */
	private int leaderId = -1;
	/** The leader name. */
	private String leaderName = "";
	/** The faction id. */
	private int factionId = -1;

	/**
	 * Creates a new Alliance.
	 */
	public Alliance() {
	}

	/**
	 * Creates a new Alliance.
	 * @param id the id
	 * @param name the name
	 * @param leaderId the leader id
	 * @param leaderName the leader name
	 * @param factionId the faction id
	 */
	public Alliance(int id, String name, int leaderId, String leaderName, int factionId) {
		setId(id);
		setName(name);
		setLeaderId(leaderId);
		setLeaderName(leaderName);
		setFactionId(factionId);
	}

	/**
	 * Creates a new Alliance.
	 * @param alliance the alliance
	 */
	public Alliance(Alliance alliance) {
		setId(alliance.getId());
		setName(alliance.getName());
		setLeaderId(alliance.getLeaderId());
		setLeaderName(alliance.getLeaderName());
		setFactionId(alliance.getFactionId());
	}

	/**
	 * Creates a new Alliance.
	 * @param iAlliance the i alliance
	 */
	public Alliance(IAlliance iAlliance) {
		setId(iAlliance.getId());
		setName(iAlliance.getName());
		setLeaderId(iAlliance.getLeaderId());
		setLeaderName(iAlliance.getLeaderName());
		setFactionId(iAlliance.getFactionId());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the leader id.
	 * @return the leader id.
	 */
	public int getLeaderId() {
		return leaderId;
	}

	/**
	 * Returns the leader name.
	 * @return the leader name.
	 */
	public String getLeaderName() {
		return leaderName;
	}

	/**
	 * Returns the faction id.
	 * @return the faction id.
	 */
	public int getFactionId() {
		return factionId;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the leader id.
	 * @param leaderId the leader id to set.
	 */
	public void setLeaderId(int leaderId) {
		this.leaderId = leaderId;
	}

	/**
	 * Sets the leader name.
	 * @param leaderName the leader name to set.
	 */
	public void setLeaderName(String leaderName) {
		this.leaderName = leaderName;
	}

	/**
	 * Sets the faction id.
	 * @param factionId the faction id to set.
	 */
	public void setFactionId(int factionId) {
		this.factionId = factionId;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(431, 37);
		hash.append(id);
		hash.append(name);
		hash.append(leaderId);
		hash.append(leaderName);
		hash.append(factionId);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Alliance) {
			Alliance compare = (Alliance) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.name, compare.name);
			equals.append(this.leaderId, compare.leaderId);
			equals.append(this.leaderName, compare.leaderName);
			equals.append(this.factionId, compare.factionId);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IAlliance compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.name, compare.getName());
		builder.append(this.leaderId, compare.getLeaderId());
		builder.append(this.leaderName, compare.getLeaderName());
		builder.append(this.factionId, compare.getFactionId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		string.append("leaderId", leaderId);
		if (leaderName != null) {
			string.append("leaderName", leaderName);
		}
		string.append("factionId", factionId);
		return string.toString();
	}
}
